<?php

namespace App\Http\Controllers\Erp;

use App\CodeResponse;
use App\Enum;
use App\Repositories\Purchase\PurchaseReturnItemRepository;
use App\Services\Purchase\PurchaseReturnItemService;
use Illuminate\Http\Request;

class PurchaseReturnItemController extends ErpController
{


    //添加采购退货产品项目明细
    protected $purchaseReturnItemRepository;

    public function __construct(PurchaseReturnItemRepository $purchaseReturnItemRepository)
    {
        $this->purchaseReturnItemRepository = $purchaseReturnItemRepository;

    }

    public function list($orderId,Request $request)
    {
        $input = $request->input();
        $where['order_id']=$orderId;
        $where['is_enable']=Enum::IS_ENABLE_TRUE;

        if(empty($input['is_all'])){
            $list = $this->purchaseReturnItemRepository->getList(['*'],$where);
            return $this->paginate($list);
        }else{
            $list = $this->purchaseReturnItemRepository->getAll($where);
            return $this->success($list);
        }

    }


    public function create($orderId,Request $request)
    {
        $input = $request->input();
        $flag= PurchaseReturnItemService::getInstance()->createItem($orderId,$input);
        return $this->failOrSuccess($flag, CodeResponse::CREATED_FAIL, $flag);

    }

    public function update($id, Request $request)
    {
        $input = $request->input();
        $flag= PurchaseReturnItemService::getInstance()->updateItem($id,$input);
        return $this->failOrSuccess($flag, CodeResponse::UPDATED_FAIL, $flag);

    }

    public function delete($id)
    {
        $flag= PurchaseReturnItemService::getInstance()->deleteItem($id);
        return $this->failOrSuccess($flag, CodeResponse::UPDATED_FAIL);

    }



}